const esbuild = require("esbuild");


//@ts-check
/** @typedef {import("esbuild").BuildOptions} esbuildConfig **/

/** @type esbuildConfig */
const option = {
	entryPoints: ["./src/Test/Index.ts"],
	outfile: "./dist/bundle.js",
	bundle: true,
	sourcemap: "linked",
	plugins: [{
		name: 'rebuild-notify',
		setup(build) {
			build.onEnd(result => {
				console.log(`build ended with ${result.errors.length} errors`);
				// HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
			})
		},
	}],
}

async function Watch() {
	let builder = await esbuild.context(option);
	await builder.watch();
	console.log("watching...");
}

Watch();